<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>用户修改</title>
    <link rel="stylesheet" type="text/css" th:href="@{/css/admin_index.css}">
</head>
<body>

    <div class="frm">
        <div class="title">用户信息修改:</div>
        <form th:action="@{/admin/user/update}" enctype="multipart/form-data" method="post">
            <table>

                <tr>
                    <td>用户id:</td>
                    <td>
                        <span th:text="${users.id}"/>
                        <input type="hidden" name="id" th:value="${users.id}"/>
                    </td>
                </tr>

                <tr>
                    <td>用户名:</td>
                    <td>
                        <input type="text" name="username" th:value="${users.username}" required="required"/>
                    </td>
                </tr>

                <tr>
                    <td>密码:</td>
                    <td>
                        <input type="password" id="password" name="password" required="required" th:value="${users.password}"  th:oninput="|clearPwd()|" th:onchange="|pwdToMd5()|"/>
                    </td>
                </tr>

                <tr>
                    <td>邮箱:</td>
                    <td>
                        <input type="text" name="email" required="required" th:value="${users.email}"/>
                    </td>
                </tr>

                <tr>
                    <td>电话:</td>
                    <td>
                        <input type="text" name="phone" required="required" th:value="${users.phone}"/>
                    </td>
                </tr>

                <tr>
                    <td>公司:</td>
                    <td>
                        <input type="text" name="company" required="required" th:value="${users.company}"/>
                    </td>
                </tr>

                <tr>
                    <td>
                        <input type="submit" value="提交">
                    </td>
                </tr>
            </table>
        </form>
    </div>

    <script src="dist/js/jquery.min.js" th:src="@{/dist/js/jquery.min.js}"></script>
    <script th:src="@{/js/md5.js}"></script>
<script type="text/javascript">
    var pwdChangeFlag = false;
    function clearPwd() {
        // 如果密码未被更改
        if (pwdChangeFlag == false) {
            // 密码设置可见
            $("#password").attr("type","text");
            // 清空输入框
            $("#password").val("");
            pwdChangeFlag = true;
        }
    }
    function pwdToMd5() {
        // 如果密码被更改了，那就重新加密
        if (pwdChangeFlag) {
            var password = hex_md5(document.getElementById("password").value);
            $("#password").val(password);
        }
    }
</script>
</body>
</html>